package drp.snowbell.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

public class ZIPResource implements IResource {
	private URI uri;
	private String name;
	private String path;

	public ZIPResource(URI uri) {
		this.uri = uri;
		path = uri.getPath();
		int pos = path.lastIndexOf('/');
		if (pos >= 0) {
			name = path.substring(pos + 1);
		} else {
			name = path;
		}

	}

	@Override
	public URI getURI() {
		return uri;
	}

	@Override
	public String getName() {

		return name;
	}

	@Override
	public String getPath() {
		return path;
	}

	@Override
	public InputStream openInputStream() {
		InputStream stream = null;
		try {
			stream = uri.toURL().openStream();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return stream;
	}

	/**
	 * zip不允许修改
	 */
	@Override
	public OutputStream openOutStream() {
		throw new NotImplementedException();
	}

	/**
	 * zip不允许修改
	 */
	@Override
	public boolean rename(String newName) {
		throw new NotImplementedException();
	}

	/**
	 * zip不允许修改
	 */
	@Override
	public boolean delete() {
		throw new NotImplementedException();
	}

}
